// const api_url = 'http://localhost:3000'
const api_url = 'http://ecourse.xqb.ink'
// const api_url = 'http://101.34.244.21'
import {
    userinfo
} from '../js/myRender.js'
// let userinfo = JSON.parse(localStorage.getItem('userinfo')) || {};

function Http({
    type = 'get',
    data = {},
    url = ''
}) {
    if (url == '') {
        alert('请正确书写一个接口地址')
        return
    }
    return new Promise((resolve, reject) => {
        $.ajax({
            url: api_url + url,
            // url,
            type,
            data,
            headers: {
                authorization: userinfo.token, //传入token
            },
            success(result) { //成功的回调
                //console.log(res, '我是结果');
                resolve({
                    err: null,
                    result
                })

            },
            error(err) { //失败的回调
                //console.log(err, '请求失败');
                resolve({
                    err
                })
            }
        })
    })
}

export default Http